package com.sky.service;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * spring redis 工具类
 *
 * @author
 **/
@Component
public class RedisCache {

    private static RedisCache redisCache;

    public static final String captcha_codes = "captcha_codes:";

    public static final String sms_captcha_codes = "sms_captcha_codes:";

    @Resource
    private RedisTemplate redisTemplate;

    @PostConstruct
    public void init(){
        redisCache = this;
        redisCache.redisTemplate = this.redisTemplate;
    }

    public static void set(String key,Object value){
        redisCache.redisTemplate.opsForValue().set(key,value);
    }

    public static void set(String key,Object value,long timeout, TimeUnit unit){
        redisCache.redisTemplate.opsForValue().set(key,value,timeout, unit);
    }

    public static Object get(String key){
        return redisCache.redisTemplate.opsForValue().get(key);
    }

    public static Boolean delete(String key){
        return redisCache.redisTemplate.delete(key);
    }
}
